package com.shudingke.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shudingke.domain.Address;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-06-29
 */
@Controller
@RequestMapping("/address")
public class AddressController {
    //添加收货地址
    @RequestMapping("/addAddress")
    public String addAddress(){
        return "addAddress";
    }
    
    //所有的收货地址列表
    @RequestMapping("/load")
    @ResponseBody
    public List<Address> load(HttpServletRequest req){
        Address address = new Address();
        QueryWrapper<Address> qw = new QueryWrapper<>();
        //查询该用户的所有收货信息
        String uuid = req.getSession().getAttribute("uid").toString();
        qw.eq("uid",Integer.parseInt(uuid));
        List<Address> list = address.selectList(qw);
        return list;
    }
    
    //修改收货信息
    @RequestMapping("/update")
    @ResponseBody
    public String update(){
        
        return "";
    }
    
    //删除收货信息
    @RequestMapping("/deleteAddress")
    @ResponseBody
    public String deleteAddress(String aid){
        Address address = new Address();
        address.setAid(Integer.parseInt(aid));
        address.deleteById();
        return "111";
    }

    //删除收货信息
    @RequestMapping("/add")
    @ResponseBody
    public String add(@RequestBody Address address, HttpServletRequest req){
        String uuid = req.getSession().getAttribute("uid").toString();
        address.setUid(Integer.parseInt(uuid));
        address.insert();
        return "111";
    }
}

